package com.yanqu.road.server.cmd.specialtombrob.specialtombrobsign;

import com.yanqu.road.entity.activity.ActivityInfo;
import com.yanqu.road.entity.enums.eActivityType;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.specialtombrob.SpecialTombRobProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.manger.activity.ActivityMgr;
import com.yanqu.road.server.manger.specialtombrob.ActivityDaySignMgr;
import com.yanqu.road.server.manger.specialtombrob.SpecialTombRobSignMgr;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.server.protocol.GameProtocol;

@Cmd(code = GameProtocol.S_SPECIAL_TOMB_ROB_SIGN,desc = "盗墓笔记特色服七日签到")
public class SpecialTombRobSignCmd extends AbstractCommand {
    private int activityId;
    private int conditionId;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        SpecialTombRobProto.SpecialTombRobSevenDaySignReq req = SpecialTombRobProto.SpecialTombRobSevenDaySignReq.parseFrom(packet.getBytes());
        activityId =req.getActivityId();
        conditionId = req.getConditionId();
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        ActivityInfo openActivityInfo = ActivityMgr.getOpenActivityInfo(activityId);
        if (openActivityInfo == null) {
            ret = GameErrorCode.E_ACTIVITY_NO_FOUND;
            return;
        }
        if (openActivityInfo.getType() == eActivityType.DaySign.getValue()) {
            ret = ActivityDaySignMgr.simpleSign(player, activityId, conditionId);
        } else {
            ret = SpecialTombRobSignMgr.simpleSign(player, activityId, conditionId);
        }
    }

    @Override
    public void sendData(GamePlayer player) {
        if (ret != 0){
            SpecialTombRobProto.SpecialTombRobSevenDaySignResp.Builder builder = SpecialTombRobProto.SpecialTombRobSevenDaySignResp.newBuilder();
            builder.setRet(ret);
            player.sendPacket(ClientProtocol.U_SPECIAL_TOMB_ROB_SIGN,builder);
        }
    }

}
